<template>
    <div class="container">
        <a-col :md="6" :sm="10">
            <a-select v-model="year" @change="changeYear">
                <a-select-option :value="1">当天</a-select-option>
                <a-select-option :value="2">本周</a-select-option>
                <a-select-option :value="3">本月</a-select-option>
                <a-select-option :value="4">本年</a-select-option>
            </a-select>
        </a-col>
        <a-col :md="18" :sm="14">
            <a-range-picker
                :value="dateValue"
                @change="changeDate"
            />
        </a-col>
    </div>
</template>

<script>
import moment from 'moment'
export default {
    name:"DateRange",
    props:{
        type:{
            type:Number,
            default:3,//默认日期
        },
        fbeginDate:{
            type:String,
            default:"fbeginDate"//返回开始时间key
        },
        fendDate:{
            type:String,
            default:"fendDate"//返回结束时间key
        }
    },
    data(){
        return{
            year:3,//当前选择
            dateValue:[]
        }
    },
    created(){
        var _this = this;
        _this.year = _this.type;
        _this.changeYear(_this.type);
    },
    methods:{
        //修改当前日期段
        changeYear(e){
            var _this = this;
            var dateArr=new Array();
            switch(e){
                case 1://当天
                    dateArr = [moment(),moment()];
                    break;
                case 2://本周
                    dateArr = [moment().week(moment().week()).startOf('week'),moment().week(moment().week()).endOf('week')];
                    break;
                case 3://本月
                    dateArr = [moment().month(moment().month()).startOf('month'),moment().month(moment().month()).endOf('month')];
                    break;
                case 4://本年
                    dateArr = [moment().year(moment().year()).startOf('year'),moment().year(moment().year()).endOf('year')];
                    break;
            }
            _this.changeRange(dateArr);
        },
        changeRange(dateArr){
            var _this = this;
            var fbeginDate = dateArr[0].format('YYYY-MM-DD');
            var fendDate = dateArr[1].format('YYYY-MM-DD');
            _this.dateValue = dateArr;
            var returnObj = new Object();
            returnObj[_this.fbeginDate] = fbeginDate;
            returnObj[_this.fendDate] = fendDate;
            _this.$emit("change",returnObj);
        },
        //修改制表日期
        changeDate(date,dateString){
            this.changeRange(date);
            // this.dateValue = date;
            // this.queryParam.fbeginDate = dateString[0];
            // this.queryParam.fendDate = dateString[1];
        },
    }
}
</script>

<style lang="less" scoped>
</style>


